﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace hse_2013_local_game2d
{
    public class Missile:Bomb
    {
        private int lifeFrameCounter;
        private int velocity;
        private Image bombImage;
        private Image explosionImage;
        private double angle;
        private Point[] destinationPoints;
        public Missile(Point position,Image explosionImage, Image bombImage,double angle,int velocity)
            : base(position,explosionImage)
        {
            this.explosionImage = explosionImage;
            this.bombImage = bombImage;
            this.angle = angle;
            this.velocity = velocity+10;
            lifeFrameCounter = 0;
            destinationPoints = new Point[3];
            destinationPoints[0] = position;
            destinationPoints[1] = new Point((int)(position.X + 20*Math.Cos(angle)), (int)(position.Y+20*Math.Sin(angle)));
            destinationPoints[2] = new Point((int)(position.X - 10 * Math.Sin(angle)), (int)(position.Y + 10 * Math.Cos(angle))); //размеры бомбы 20*10
        }
        public override void Move()
        {
            if (!burnMode)
            {
                bPosition = new Point((int)(bPosition.X + velocity * Math.Cos(angle)), (int)(bPosition.Y + velocity * Math.Sin(angle)));
                destinationPoints[0] = bPosition;
                destinationPoints[1] = new Point((int)(bPosition.X + 20 * Math.Cos(angle)), (int)(bPosition.Y + 20 * Math.Sin(angle)));
                destinationPoints[2] = new Point((int)(bPosition.X - 10 * Math.Sin(angle)), (int)(bPosition.Y + 10 * Math.Cos(angle)));
                if (lifeFrameCounter > 40)
                { ExplosionOccured(this); }
                else
                { lifeFrameCounter++; }

            }
            else
            {
                angle = 0;
                destinationPoints[0] = new Point(bPosition.X - 30, bPosition.Y - 30);
                destinationPoints[1] = new Point((int)(bPosition.X + 20 * Math.Cos(angle) + 30), (int)(bPosition.Y + 20 * Math.Sin(angle) - 30));
                destinationPoints[2] = new Point((int)(bPosition.X - 10 * Math.Sin(angle) - 30), (int)(bPosition.Y + 10 * Math.Cos(angle) + 30));
            }
        }

        public override void OnPaint(Graphics g)
        {
            if (!BurnMode)
            {
                g.DrawImage(bombImage, destinationPoints);
            }
            else
            {
                explosionFrameCounter++;
                g.DrawImage(explosionImage, destinationPoints);
            }
        }
    }
}
